﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MyServer.Common;
using System.Net;
using System.Net.Sockets;
using FrameWork.Setting;


namespace MyServer.TcpIP
{
    /// <summary>
    /// 表示一个TcpIp的数据发送器
    /// </summary>
    /// <remarks>
    /// TcpIp数据发送器配套TcpIp数据读取器使用，使用其它读取器可能会出现意想不到的问题
    /// </remarks>
    [SettingParentDefine]
    public class TcpIpDataSender : DataSenderBase
    {
        private object lockObj = new object();
        public TcpIpDataSender(TcpIpCenter Center, DataCompressorBase Compressor = null) : base(Center, Compressor) { }


        protected override void SendData(object Tag, byte[] Data)
        {
            lock (lockObj)
            {
                TcpClient client = (TcpClient)(Tag);
                client.GetStream().Write(Data, 0, Data.Length);
            }
        }
    }
}
